<?php

use console\db\Migration;
use yii\db\Query;

/**
 * 用户收件地址地区编码格式化
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m300000_000015_t_user_address_rename extends Migration {

    /**
     * @inheritdoc
     */
    public $tableName = '{{%user_address}}';

    /**
     * @inheritdoc
     */
    public function safeUp() {
        $replaces = $this->getData('dist_replace.php');
        $keys = ['province', 'city', 'district'];
        foreach ($replaces as $dist) {
            Yii::error([
                'upsert' => array_combine($keys, array_keys($dist)),
                'condition' => array_combine($keys, array_values($dist)),
            ]);
            $this->update($this->tableName, array_combine($keys, array_keys($dist)), array_combine($keys, array_values($dist)));
        }
    }

}
